const net = require('net');

function checkPort(port) {
  return new Promise((resolve) => {
    const server = net.createServer();
    
    server.listen(port, () => {
      server.once('close', () => {
        resolve(true); // 端口可用
      });
      server.close();
    });
    
    server.on('error', () => {
      resolve(false); // 端口被占用
    });
  });
}

async function main() {
  console.log('检查端口状态...');
  
  const ports = [4000, 5001, 8102];
  
  for (const port of ports) {
    const isAvailable = await checkPort(port);
    console.log(`端口 ${port}: ${isAvailable ? '✅ 可用' : '❌ 被占用'}`);
  }
}

main().catch(console.error);
